using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class LbsPeopleListItem : UserControl
	{
		public delegate void ListItemClick(object sender, object object_0);
		private int mNID;
		public static bool sBIsScroling = false;
		public static uint mFindType = 1u;
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(LbsPeople), typeof(LbsPeopleListItem), new PropertyMetadata(null, new PropertyChangedCallback(LbsPeopleListItem.OnItemPropertyChanged)));
		public static long sLTimeComsume = 0L;
		public static int sNCount = 0;
		private static int sNInstanceID = 0;
		private static Dictionary<int, LbsPeopleListItem> sDictItemIsShown = new Dictionary<int, LbsPeopleListItem>();
		internal ClickEffectGrid btnLayoutRoot;
		internal Grid LayoutRoot;
		internal StackPanel panelNickName;
		internal EmojiText txtNickName;
		internal Image imgSex;
		internal TextBlock txtFriendTag;
		internal Image imgHead;
		internal Image imgVerifyTag;
		internal Image imgCircleIcon;
		internal EmojiText txtSignature;
		private bool _contentLoaded;
		public event LbsPeopleListItem.ListItemClick ItemClick;
		public LbsPeople ItemObject
		{
			get
			{
				return (LbsPeople)base.GetValue(LbsPeopleListItem.ListItemProperty);
			}
			set
			{
				base.SetValue(LbsPeopleListItem.ListItemProperty, value);
			}
		}
		public LbsPeopleListItem()
		{
			this.mNID = LbsPeopleListItem.sNInstanceID++;
			this.InitializeComponent();
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			base.add_Loaded(new RoutedEventHandler(this.LbsPeopleListItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.LbsPeopleListItem_Unloaded));
		}
		private void LbsPeopleListItem_Unloaded(object sender, RoutedEventArgs e)
		{
			if (LbsPeopleListItem.sDictItemIsShown.ContainsKey(this.mNID))
			{
				LbsPeopleListItem.sDictItemIsShown.Remove(this.mNID);
			}
		}
		private void LbsPeopleListItem_Loaded(object sender, RoutedEventArgs e)
		{
			if (!LbsPeopleListItem.sDictItemIsShown.ContainsKey(this.mNID))
			{
				LbsPeopleListItem.sDictItemIsShown.Add(this.mNID, this);
			}
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == LbsPeopleListItem.ListItemProperty)
			{
				(dependencyObject_0 as LbsPeopleListItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as LbsPeople);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}
		private void RefreshItem(LbsPeople item)
		{
			this.refreshVerifyTag(item);
			if (item == null)
			{
				return;
			}
			long ticks = DateTime.get_Now().get_Ticks();
			this.txtSignature.Text = item.strSignature;
			this.imgHead.set_Source(HeadImgMgr.getCacheHeadImage(item));
			Contact contact = StorageMgr.contact.method_0(item.strUserName);
			if (contact != null && ContactMgr.isContact(contact))
			{
				this.txtFriendTag.set_Visibility(0);
				this.txtNickName.set_MaxWidth(this.panelNickName.get_Width() - this.txtFriendTag.get_ActualWidth() - 50.0);
			}
			else
			{
				this.txtNickName.set_MaxWidth(this.panelNickName.get_Width() - 50.0);
				this.txtFriendTag.set_Visibility(1);
			}
			if (1u == LbsPeopleListItem.mFindType)
			{
				if (1 == item.nSex)
				{
					this.imgSex.set_Visibility(0);
					this.imgSex.set_Source(ImageCacheMgr.loadFromRes(MMTheme.GetInstance().sexIcon_man));
				}
				else
				{
					if (2 == item.nSex)
					{
						this.imgSex.set_Visibility(0);
						this.imgSex.set_Source(ImageCacheMgr.loadFromRes(MMTheme.GetInstance().sexIcon_woman));
					}
					else
					{
						this.imgSex.set_Visibility(1);
					}
				}
			}
			else
			{
				this.imgSex.set_Visibility(1);
			}
			this.txtNickName.Text = item.strNickName;
			long ticks2 = DateTime.get_Now().get_Ticks();
			LbsPeopleListItem.sLTimeComsume += ticks2 - ticks;
			LbsPeopleListItem.sNCount++;
			if (item.nSnsFlag == 1u)
			{
				this.imgCircleIcon.set_Visibility(0);
				return;
			}
			this.imgCircleIcon.set_Visibility(1);
		}
		private void refreshVerifyTag(LbsPeople item)
		{
			if (item != null && item.nVerifyFlag != 0u)
			{
				if (this.imgVerifyTag.get_Source() == null)
				{
					this.imgVerifyTag.set_Source(ToolFunction.GetImgFromContentSource("/Resource/Img/ContactList/VerifyTag.png"));
				}
				this.imgVerifyTag.set_Visibility(0);
				return;
			}
			this.imgVerifyTag.set_Visibility(1);
		}
		public static void RequestHeadImgInView()
		{
			List<LbsPeopleListItem> list = Enumerable.ToList<LbsPeopleListItem>(LbsPeopleListItem.sDictItemIsShown.get_Values());
			list.Reverse();
			using (List<LbsPeopleListItem>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					LbsPeopleListItem current = enumerator.get_Current();
					if (current.ItemObject != null && current.ItemObject.strUserName != null)
					{
						if (current.ItemObject.headImgStatus == ContactHeadStatus.HEAD_IMAGE_STATUS_NONE)
						{
							current.ItemObject.headImgStatus = ContactHeadStatus.HEAD_IMAGE_STATUS_FETCHING;
							HeadImgMgr.getHeadImage(current.ItemObject);
						}
						else
						{
							current.imgHead.set_Source(HeadImgMgr.getHeadImage(current.ItemObject));
						}
					}
				}
			}
		}
		public static void ShowInViewItemsCachedImg()
		{
			List<LbsPeopleListItem> list = Enumerable.ToList<LbsPeopleListItem>(LbsPeopleListItem.sDictItemIsShown.get_Values());
			using (List<LbsPeopleListItem>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					LbsPeopleListItem current = enumerator.get_Current();
					if (current.ItemObject != null && current.ItemObject.strUserName != null)
					{
						BitmapImage cacheHeadImage = HeadImgMgr.getCacheHeadImage(current.ItemObject);
						if (cacheHeadImage != current.imgHead.get_Source())
						{
							current.imgHead.set_Source(cacheHeadImage);
						}
					}
				}
			}
		}
		public static void RefreshHeadImgInView(List<string> listUserGetHeadImg)
		{
			if (listUserGetHeadImg == null)
			{
				return;
			}
			IEnumerable<LbsPeopleListItem> values = LbsPeopleListItem.sDictItemIsShown.get_Values();
			Enumerable.Reverse<LbsPeopleListItem>(values);
			using (List<string>.Enumerator enumerator = listUserGetHeadImg.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null)
					{
						using (IEnumerator<LbsPeopleListItem> enumerator2 = values.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								LbsPeopleListItem current2 = enumerator2.get_Current();
								if (current2.ItemObject.strUserName == current)
								{
									current2.imgHead.set_Source(HeadImgMgr.getHeadImage(current2.ItemObject));
								}
							}
						}
					}
				}
			}
		}
		private void btnLayoutRoot_Click(object sender, object object_0)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.ItemObject);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Lbs/UI/LbsPeopleListItem.xaml", 2));
			this.btnLayoutRoot = (ClickEffectGrid)base.FindName("btnLayoutRoot");
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelNickName = (StackPanel)base.FindName("panelNickName");
			this.txtNickName = (EmojiText)base.FindName("txtNickName");
			this.imgSex = (Image)base.FindName("imgSex");
			this.txtFriendTag = (TextBlock)base.FindName("txtFriendTag");
			this.imgHead = (Image)base.FindName("imgHead");
			this.imgVerifyTag = (Image)base.FindName("imgVerifyTag");
			this.imgCircleIcon = (Image)base.FindName("imgCircleIcon");
			this.txtSignature = (EmojiText)base.FindName("txtSignature");
		}
	}
}
